------------------------------------------------------------------------------
-- FILE: ~reissing/prokurs/Blatt6/Ada_Tokenizer.ads
--
--   Copyright (c) 2000 Uni Stgt.
--   All rights reserved..
--
-- PROJECT:  Programmierkurs, Blatt 6
-- VERSION:  $Id $
-- CREATED:  Tue Jan 23 10:51:45 CET 2001
-- AUTHOR:   Ralf Reissing
--
-- DESCRIPTION:
--   Abstract data object for tokenizing an Ada program. The
--   procedure Get_Token returns the tokens, i.e.
--   * the type of the token (Token_Type) and
--   * its value (String)
-- USAGE:
--   First a file is opened using Open_Input. After this,
--   Token_Available, Get_Token und Current_Line may be called. Finally,
--   Close_Input must be called to close the file.
--   Ada comments are ignored while tokenizing.
--
-- MODIFICATIONS:
--   +2007-08-27 MK: Added a Get_Token procedure that returns the column
--     of the current token.
------------------------------------------------------------------------------

with Ada_Lexer;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

package Ada_Tokenizer is

  -- Token_Type enumerates the possible kinds of tokens.
  -- Token_Type simply renames the Ada_Tokens type from the package Ada_Lexer
  -- see Ada_Lexer for details.
  type Token_Type is new Ada_Lexer.Ada_Token;

  ----------------------------------------------------------------------------
  -- PROCEDURE: Open_Input
  --
  -- DESCRIPTION:
  --   Opens the file filename and returns whether the file could be opened
  --   successfully
  -- PARAMETER:
  --   Filename - the Filename
  --   Success  - tells if the file could be opened successfully
  procedure Open_Input (Filename: in      String;
                        Success :     out Boolean);

  ----------------------------------------------------------------------------
  -- PROCEDURE: Close_Input
  --
  -- DESCRIPTION:
  --   Closes the file opened with OpenInput.
  -- USAGE:
  --   Open_Input must have been called successfully
  procedure Close_Input;

  ----------------------------------------------------------------------------
  -- FUNCTION: Token_Available
  --
  -- DESCRIPTION:
  --   Checks if a token can be read
  -- USAGE:
  --   Open_Input must have been called successfully
  -- RETURN:
  --   true, if a token can be read
  --   false, else (EOF)
  function Token_Available
    return Boolean;

  ----------------------------------------------------------------------------
  -- PROCEDURE: Get_Token
  --
  -- DESCRIPTION:
  --   Returns information about the current token
  --   AND advances the file pointer to the next token.
  -- USAGE:
  --   Open_Input must have been called successfully,
  --   Token_Available must be true
  -- PARAMETER:
  --    Kind - the kind of the tokem
  --    Value - the string value (representation) of the token
  --    Line - the line number of the token
  procedure Get_Token (Kind : out Token_Type;
                       Value: out Unbounded_String;
                       Line : out Positive);

  --  ------------------------------------------------------------------------
  --  PROCEDURE: Look_Ahead
  --  DESCRIPTION:
  --    Looks ahead amount of tokens specified if possible.
  --  PARAMETER:
  --    +Kind: The token's type read
  --    +Value: The token's value
  --    +Line: The line the token was read
  --    +Success: True if look ahead was possible, otherwise False.
  --    +Tokens: Number of tokens to look ahead.
  procedure Look_Ahead
     (Kind   : out Token_Type;
      Value  : out Unbounded_String;
      Line   : out Positive;
      Success: out Boolean;
      Tokens : in Positive := 1);

end Ada_Tokenizer;
